<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-8-2
 * Time: 上午9:48
 */

/**
 * @var \yii\web\View $this
 * @var \admin\modules\rbac\forms\UserRole $model
 * @var string $attribute
 * @var string $show_attribute
 */

use yii\bootstrap\Html;

//echo "<pre>";
//var_dump($model->$attribute);exit;
?>

<div class="widget-group-checkbox-index">
    <div class="form-group">
        <?php foreach ($model->$show_attribute as $k => $v): ?>
            <?php if ($k): ?>
                <h4>分组: <label for="" class="checkbox-group-check-label"><?= Html::checkbox("group_check_".$k); ?><?= $k ?></label></h4>
            <?php else: ?>
                <h4>全选: <label for="" class="checkbox-group-check-label"><?= Html::checkbox("group_check_".$k); ?><?= $k ?></label></h4>
            <?php endif; ?>
            <div class="" style="padding-left: 2em;" data-group_check="group_check_<?= $k ?>">
                <?=$this->render('tree-check', [
                    'tree_data' => $v,
                    'model' => $model,
                    'attribute' => $attribute,
                ]) ?>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<?php \common\components\widgets\JsBlock::begin(); ?>
    <script>
        $(function () {
            $(".checkbox-group-check-label").click(function () {
                // 全选/全不选
                var checkbox = $(this).find("input:checkbox");
                var data_group_check = checkbox.attr('name');
                if (checkbox.prop("checked")){
                    $("div[data-group_check='"+data_group_check+"']").find("input:checkbox").prop("checked", true);
                }else{
                    $("div[data-group_check='"+data_group_check+"']").find("input:checkbox").prop("checked", false);
                }
            });
        });
    </script>
<?php \common\components\widgets\JsBlock::end(); ?>